// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"errors"
	"fmt"
	"server/components/models/ent/predicate"
	"server/components/models/ent/region"
	"server/components/models/ent/regiontype"
	"server/components/models/ent/schema"
	"server/components/models/ent/user"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)

// RegionUpdate is the builder for updating Region entities.
type RegionUpdate struct {
	config
	hooks    []Hook
	mutation *RegionMutation
}

// Where appends a list predicates to the RegionUpdate builder.
func (ru *RegionUpdate) Where(ps ...predicate.Region) *RegionUpdate {
	ru.mutation.Where(ps...)
	return ru
}

// SetName sets the "name" field.
func (ru *RegionUpdate) SetName(s string) *RegionUpdate {
	ru.mutation.SetName(s)
	return ru
}

// SetNillableName sets the "name" field if the given value is not nil.
func (ru *RegionUpdate) SetNillableName(s *string) *RegionUpdate {
	if s != nil {
		ru.SetName(*s)
	}
	return ru
}

// SetParentRegion sets the "parentRegion" field.
func (ru *RegionUpdate) SetParentRegion(s string) *RegionUpdate {
	ru.mutation.SetParentRegion(s)
	return ru
}

// SetNillableParentRegion sets the "parentRegion" field if the given value is not nil.
func (ru *RegionUpdate) SetNillableParentRegion(s *string) *RegionUpdate {
	if s != nil {
		ru.SetParentRegion(*s)
	}
	return ru
}

// ClearParentRegion clears the value of the "parentRegion" field.
func (ru *RegionUpdate) ClearParentRegion() *RegionUpdate {
	ru.mutation.ClearParentRegion()
	return ru
}

// SetLatitude1 sets the "latitude1" field.
func (ru *RegionUpdate) SetLatitude1(f float64) *RegionUpdate {
	ru.mutation.ResetLatitude1()
	ru.mutation.SetLatitude1(f)
	return ru
}

// SetNillableLatitude1 sets the "latitude1" field if the given value is not nil.
func (ru *RegionUpdate) SetNillableLatitude1(f *float64) *RegionUpdate {
	if f != nil {
		ru.SetLatitude1(*f)
	}
	return ru
}

// AddLatitude1 adds f to the "latitude1" field.
func (ru *RegionUpdate) AddLatitude1(f float64) *RegionUpdate {
	ru.mutation.AddLatitude1(f)
	return ru
}

// ClearLatitude1 clears the value of the "latitude1" field.
func (ru *RegionUpdate) ClearLatitude1() *RegionUpdate {
	ru.mutation.ClearLatitude1()
	return ru
}

// SetLongitude1 sets the "longitude1" field.
func (ru *RegionUpdate) SetLongitude1(f float64) *RegionUpdate {
	ru.mutation.ResetLongitude1()
	ru.mutation.SetLongitude1(f)
	return ru
}

// SetNillableLongitude1 sets the "longitude1" field if the given value is not nil.
func (ru *RegionUpdate) SetNillableLongitude1(f *float64) *RegionUpdate {
	if f != nil {
		ru.SetLongitude1(*f)
	}
	return ru
}

// AddLongitude1 adds f to the "longitude1" field.
func (ru *RegionUpdate) AddLongitude1(f float64) *RegionUpdate {
	ru.mutation.AddLongitude1(f)
	return ru
}

// ClearLongitude1 clears the value of the "longitude1" field.
func (ru *RegionUpdate) ClearLongitude1() *RegionUpdate {
	ru.mutation.ClearLongitude1()
	return ru
}

// SetLatitude2 sets the "latitude2" field.
func (ru *RegionUpdate) SetLatitude2(f float64) *RegionUpdate {
	ru.mutation.ResetLatitude2()
	ru.mutation.SetLatitude2(f)
	return ru
}

// SetNillableLatitude2 sets the "latitude2" field if the given value is not nil.
func (ru *RegionUpdate) SetNillableLatitude2(f *float64) *RegionUpdate {
	if f != nil {
		ru.SetLatitude2(*f)
	}
	return ru
}

// AddLatitude2 adds f to the "latitude2" field.
func (ru *RegionUpdate) AddLatitude2(f float64) *RegionUpdate {
	ru.mutation.AddLatitude2(f)
	return ru
}

// ClearLatitude2 clears the value of the "latitude2" field.
func (ru *RegionUpdate) ClearLatitude2() *RegionUpdate {
	ru.mutation.ClearLatitude2()
	return ru
}

// SetLongitude2 sets the "longitude2" field.
func (ru *RegionUpdate) SetLongitude2(f float64) *RegionUpdate {
	ru.mutation.ResetLongitude2()
	ru.mutation.SetLongitude2(f)
	return ru
}

// SetNillableLongitude2 sets the "longitude2" field if the given value is not nil.
func (ru *RegionUpdate) SetNillableLongitude2(f *float64) *RegionUpdate {
	if f != nil {
		ru.SetLongitude2(*f)
	}
	return ru
}

// AddLongitude2 adds f to the "longitude2" field.
func (ru *RegionUpdate) AddLongitude2(f float64) *RegionUpdate {
	ru.mutation.AddLongitude2(f)
	return ru
}

// ClearLongitude2 clears the value of the "longitude2" field.
func (ru *RegionUpdate) ClearLongitude2() *RegionUpdate {
	ru.mutation.ClearLongitude2()
	return ru
}

// SetOsmData sets the "osmData" field.
func (ru *RegionUpdate) SetOsmData(sd schema.OsmData) *RegionUpdate {
	ru.mutation.SetOsmData(sd)
	return ru
}

// SetNillableOsmData sets the "osmData" field if the given value is not nil.
func (ru *RegionUpdate) SetNillableOsmData(sd *schema.OsmData) *RegionUpdate {
	if sd != nil {
		ru.SetOsmData(*sd)
	}
	return ru
}

// ClearOsmData clears the value of the "osmData" field.
func (ru *RegionUpdate) ClearOsmData() *RegionUpdate {
	ru.mutation.ClearOsmData()
	return ru
}

// SetRegionTypeID sets the "regionType" edge to the RegionType entity by ID.
func (ru *RegionUpdate) SetRegionTypeID(id int64) *RegionUpdate {
	ru.mutation.SetRegionTypeID(id)
	return ru
}

// SetNillableRegionTypeID sets the "regionType" edge to the RegionType entity by ID if the given value is not nil.
func (ru *RegionUpdate) SetNillableRegionTypeID(id *int64) *RegionUpdate {
	if id != nil {
		ru = ru.SetRegionTypeID(*id)
	}
	return ru
}

// SetRegionType sets the "regionType" edge to the RegionType entity.
func (ru *RegionUpdate) SetRegionType(r *RegionType) *RegionUpdate {
	return ru.SetRegionTypeID(r.ID)
}

// SetAccountIdID sets the "accountId" edge to the User entity by ID.
func (ru *RegionUpdate) SetAccountIdID(id int) *RegionUpdate {
	ru.mutation.SetAccountIdID(id)
	return ru
}

// SetNillableAccountIdID sets the "accountId" edge to the User entity by ID if the given value is not nil.
func (ru *RegionUpdate) SetNillableAccountIdID(id *int) *RegionUpdate {
	if id != nil {
		ru = ru.SetAccountIdID(*id)
	}
	return ru
}

// SetAccountId sets the "accountId" edge to the User entity.
func (ru *RegionUpdate) SetAccountId(u *User) *RegionUpdate {
	return ru.SetAccountIdID(u.ID)
}

// Mutation returns the RegionMutation object of the builder.
func (ru *RegionUpdate) Mutation() *RegionMutation {
	return ru.mutation
}

// ClearRegionType clears the "regionType" edge to the RegionType entity.
func (ru *RegionUpdate) ClearRegionType() *RegionUpdate {
	ru.mutation.ClearRegionType()
	return ru
}

// ClearAccountId clears the "accountId" edge to the User entity.
func (ru *RegionUpdate) ClearAccountId() *RegionUpdate {
	ru.mutation.ClearAccountId()
	return ru
}

// Save executes the query and returns the number of nodes affected by the update operation.
func (ru *RegionUpdate) Save(ctx context.Context) (int, error) {
	return withHooks(ctx, ru.sqlSave, ru.mutation, ru.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (ru *RegionUpdate) SaveX(ctx context.Context) int {
	affected, err := ru.Save(ctx)
	if err != nil {
		panic(err)
	}
	return affected
}

// Exec executes the query.
func (ru *RegionUpdate) Exec(ctx context.Context) error {
	_, err := ru.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (ru *RegionUpdate) ExecX(ctx context.Context) {
	if err := ru.Exec(ctx); err != nil {
		panic(err)
	}
}

func (ru *RegionUpdate) sqlSave(ctx context.Context) (n int, err error) {
	_spec := sqlgraph.NewUpdateSpec(region.Table, region.Columns, sqlgraph.NewFieldSpec(region.FieldID, field.TypeInt64))
	if ps := ru.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := ru.mutation.Name(); ok {
		_spec.SetField(region.FieldName, field.TypeString, value)
	}
	if value, ok := ru.mutation.ParentRegion(); ok {
		_spec.SetField(region.FieldParentRegion, field.TypeString, value)
	}
	if ru.mutation.ParentRegionCleared() {
		_spec.ClearField(region.FieldParentRegion, field.TypeString)
	}
	if value, ok := ru.mutation.Latitude1(); ok {
		_spec.SetField(region.FieldLatitude1, field.TypeFloat64, value)
	}
	if value, ok := ru.mutation.AddedLatitude1(); ok {
		_spec.AddField(region.FieldLatitude1, field.TypeFloat64, value)
	}
	if ru.mutation.Latitude1Cleared() {
		_spec.ClearField(region.FieldLatitude1, field.TypeFloat64)
	}
	if value, ok := ru.mutation.Longitude1(); ok {
		_spec.SetField(region.FieldLongitude1, field.TypeFloat64, value)
	}
	if value, ok := ru.mutation.AddedLongitude1(); ok {
		_spec.AddField(region.FieldLongitude1, field.TypeFloat64, value)
	}
	if ru.mutation.Longitude1Cleared() {
		_spec.ClearField(region.FieldLongitude1, field.TypeFloat64)
	}
	if value, ok := ru.mutation.Latitude2(); ok {
		_spec.SetField(region.FieldLatitude2, field.TypeFloat64, value)
	}
	if value, ok := ru.mutation.AddedLatitude2(); ok {
		_spec.AddField(region.FieldLatitude2, field.TypeFloat64, value)
	}
	if ru.mutation.Latitude2Cleared() {
		_spec.ClearField(region.FieldLatitude2, field.TypeFloat64)
	}
	if value, ok := ru.mutation.Longitude2(); ok {
		_spec.SetField(region.FieldLongitude2, field.TypeFloat64, value)
	}
	if value, ok := ru.mutation.AddedLongitude2(); ok {
		_spec.AddField(region.FieldLongitude2, field.TypeFloat64, value)
	}
	if ru.mutation.Longitude2Cleared() {
		_spec.ClearField(region.FieldLongitude2, field.TypeFloat64)
	}
	if value, ok := ru.mutation.OsmData(); ok {
		_spec.SetField(region.FieldOsmData, field.TypeJSON, value)
	}
	if ru.mutation.OsmDataCleared() {
		_spec.ClearField(region.FieldOsmData, field.TypeJSON)
	}
	if ru.mutation.RegionTypeCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   region.RegionTypeTable,
			Columns: []string{region.RegionTypeColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(regiontype.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ru.mutation.RegionTypeIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   region.RegionTypeTable,
			Columns: []string{region.RegionTypeColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(regiontype.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if ru.mutation.AccountIdCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   region.AccountIdTable,
			Columns: []string{region.AccountIdColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ru.mutation.AccountIdIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   region.AccountIdTable,
			Columns: []string{region.AccountIdColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if n, err = sqlgraph.UpdateNodes(ctx, ru.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{region.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return 0, err
	}
	ru.mutation.done = true
	return n, nil
}

// RegionUpdateOne is the builder for updating a single Region entity.
type RegionUpdateOne struct {
	config
	fields   []string
	hooks    []Hook
	mutation *RegionMutation
}

// SetName sets the "name" field.
func (ruo *RegionUpdateOne) SetName(s string) *RegionUpdateOne {
	ruo.mutation.SetName(s)
	return ruo
}

// SetNillableName sets the "name" field if the given value is not nil.
func (ruo *RegionUpdateOne) SetNillableName(s *string) *RegionUpdateOne {
	if s != nil {
		ruo.SetName(*s)
	}
	return ruo
}

// SetParentRegion sets the "parentRegion" field.
func (ruo *RegionUpdateOne) SetParentRegion(s string) *RegionUpdateOne {
	ruo.mutation.SetParentRegion(s)
	return ruo
}

// SetNillableParentRegion sets the "parentRegion" field if the given value is not nil.
func (ruo *RegionUpdateOne) SetNillableParentRegion(s *string) *RegionUpdateOne {
	if s != nil {
		ruo.SetParentRegion(*s)
	}
	return ruo
}

// ClearParentRegion clears the value of the "parentRegion" field.
func (ruo *RegionUpdateOne) ClearParentRegion() *RegionUpdateOne {
	ruo.mutation.ClearParentRegion()
	return ruo
}

// SetLatitude1 sets the "latitude1" field.
func (ruo *RegionUpdateOne) SetLatitude1(f float64) *RegionUpdateOne {
	ruo.mutation.ResetLatitude1()
	ruo.mutation.SetLatitude1(f)
	return ruo
}

// SetNillableLatitude1 sets the "latitude1" field if the given value is not nil.
func (ruo *RegionUpdateOne) SetNillableLatitude1(f *float64) *RegionUpdateOne {
	if f != nil {
		ruo.SetLatitude1(*f)
	}
	return ruo
}

// AddLatitude1 adds f to the "latitude1" field.
func (ruo *RegionUpdateOne) AddLatitude1(f float64) *RegionUpdateOne {
	ruo.mutation.AddLatitude1(f)
	return ruo
}

// ClearLatitude1 clears the value of the "latitude1" field.
func (ruo *RegionUpdateOne) ClearLatitude1() *RegionUpdateOne {
	ruo.mutation.ClearLatitude1()
	return ruo
}

// SetLongitude1 sets the "longitude1" field.
func (ruo *RegionUpdateOne) SetLongitude1(f float64) *RegionUpdateOne {
	ruo.mutation.ResetLongitude1()
	ruo.mutation.SetLongitude1(f)
	return ruo
}

// SetNillableLongitude1 sets the "longitude1" field if the given value is not nil.
func (ruo *RegionUpdateOne) SetNillableLongitude1(f *float64) *RegionUpdateOne {
	if f != nil {
		ruo.SetLongitude1(*f)
	}
	return ruo
}

// AddLongitude1 adds f to the "longitude1" field.
func (ruo *RegionUpdateOne) AddLongitude1(f float64) *RegionUpdateOne {
	ruo.mutation.AddLongitude1(f)
	return ruo
}

// ClearLongitude1 clears the value of the "longitude1" field.
func (ruo *RegionUpdateOne) ClearLongitude1() *RegionUpdateOne {
	ruo.mutation.ClearLongitude1()
	return ruo
}

// SetLatitude2 sets the "latitude2" field.
func (ruo *RegionUpdateOne) SetLatitude2(f float64) *RegionUpdateOne {
	ruo.mutation.ResetLatitude2()
	ruo.mutation.SetLatitude2(f)
	return ruo
}

// SetNillableLatitude2 sets the "latitude2" field if the given value is not nil.
func (ruo *RegionUpdateOne) SetNillableLatitude2(f *float64) *RegionUpdateOne {
	if f != nil {
		ruo.SetLatitude2(*f)
	}
	return ruo
}

// AddLatitude2 adds f to the "latitude2" field.
func (ruo *RegionUpdateOne) AddLatitude2(f float64) *RegionUpdateOne {
	ruo.mutation.AddLatitude2(f)
	return ruo
}

// ClearLatitude2 clears the value of the "latitude2" field.
func (ruo *RegionUpdateOne) ClearLatitude2() *RegionUpdateOne {
	ruo.mutation.ClearLatitude2()
	return ruo
}

// SetLongitude2 sets the "longitude2" field.
func (ruo *RegionUpdateOne) SetLongitude2(f float64) *RegionUpdateOne {
	ruo.mutation.ResetLongitude2()
	ruo.mutation.SetLongitude2(f)
	return ruo
}

// SetNillableLongitude2 sets the "longitude2" field if the given value is not nil.
func (ruo *RegionUpdateOne) SetNillableLongitude2(f *float64) *RegionUpdateOne {
	if f != nil {
		ruo.SetLongitude2(*f)
	}
	return ruo
}

// AddLongitude2 adds f to the "longitude2" field.
func (ruo *RegionUpdateOne) AddLongitude2(f float64) *RegionUpdateOne {
	ruo.mutation.AddLongitude2(f)
	return ruo
}

// ClearLongitude2 clears the value of the "longitude2" field.
func (ruo *RegionUpdateOne) ClearLongitude2() *RegionUpdateOne {
	ruo.mutation.ClearLongitude2()
	return ruo
}

// SetOsmData sets the "osmData" field.
func (ruo *RegionUpdateOne) SetOsmData(sd schema.OsmData) *RegionUpdateOne {
	ruo.mutation.SetOsmData(sd)
	return ruo
}

// SetNillableOsmData sets the "osmData" field if the given value is not nil.
func (ruo *RegionUpdateOne) SetNillableOsmData(sd *schema.OsmData) *RegionUpdateOne {
	if sd != nil {
		ruo.SetOsmData(*sd)
	}
	return ruo
}

// ClearOsmData clears the value of the "osmData" field.
func (ruo *RegionUpdateOne) ClearOsmData() *RegionUpdateOne {
	ruo.mutation.ClearOsmData()
	return ruo
}

// SetRegionTypeID sets the "regionType" edge to the RegionType entity by ID.
func (ruo *RegionUpdateOne) SetRegionTypeID(id int64) *RegionUpdateOne {
	ruo.mutation.SetRegionTypeID(id)
	return ruo
}

// SetNillableRegionTypeID sets the "regionType" edge to the RegionType entity by ID if the given value is not nil.
func (ruo *RegionUpdateOne) SetNillableRegionTypeID(id *int64) *RegionUpdateOne {
	if id != nil {
		ruo = ruo.SetRegionTypeID(*id)
	}
	return ruo
}

// SetRegionType sets the "regionType" edge to the RegionType entity.
func (ruo *RegionUpdateOne) SetRegionType(r *RegionType) *RegionUpdateOne {
	return ruo.SetRegionTypeID(r.ID)
}

// SetAccountIdID sets the "accountId" edge to the User entity by ID.
func (ruo *RegionUpdateOne) SetAccountIdID(id int) *RegionUpdateOne {
	ruo.mutation.SetAccountIdID(id)
	return ruo
}

// SetNillableAccountIdID sets the "accountId" edge to the User entity by ID if the given value is not nil.
func (ruo *RegionUpdateOne) SetNillableAccountIdID(id *int) *RegionUpdateOne {
	if id != nil {
		ruo = ruo.SetAccountIdID(*id)
	}
	return ruo
}

// SetAccountId sets the "accountId" edge to the User entity.
func (ruo *RegionUpdateOne) SetAccountId(u *User) *RegionUpdateOne {
	return ruo.SetAccountIdID(u.ID)
}

// Mutation returns the RegionMutation object of the builder.
func (ruo *RegionUpdateOne) Mutation() *RegionMutation {
	return ruo.mutation
}

// ClearRegionType clears the "regionType" edge to the RegionType entity.
func (ruo *RegionUpdateOne) ClearRegionType() *RegionUpdateOne {
	ruo.mutation.ClearRegionType()
	return ruo
}

// ClearAccountId clears the "accountId" edge to the User entity.
func (ruo *RegionUpdateOne) ClearAccountId() *RegionUpdateOne {
	ruo.mutation.ClearAccountId()
	return ruo
}

// Where appends a list predicates to the RegionUpdate builder.
func (ruo *RegionUpdateOne) Where(ps ...predicate.Region) *RegionUpdateOne {
	ruo.mutation.Where(ps...)
	return ruo
}

// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (ruo *RegionUpdateOne) Select(field string, fields ...string) *RegionUpdateOne {
	ruo.fields = append([]string{field}, fields...)
	return ruo
}

// Save executes the query and returns the updated Region entity.
func (ruo *RegionUpdateOne) Save(ctx context.Context) (*Region, error) {
	return withHooks(ctx, ruo.sqlSave, ruo.mutation, ruo.hooks)
}

// SaveX is like Save, but panics if an error occurs.
func (ruo *RegionUpdateOne) SaveX(ctx context.Context) *Region {
	node, err := ruo.Save(ctx)
	if err != nil {
		panic(err)
	}
	return node
}

// Exec executes the query on the entity.
func (ruo *RegionUpdateOne) Exec(ctx context.Context) error {
	_, err := ruo.Save(ctx)
	return err
}

// ExecX is like Exec, but panics if an error occurs.
func (ruo *RegionUpdateOne) ExecX(ctx context.Context) {
	if err := ruo.Exec(ctx); err != nil {
		panic(err)
	}
}

func (ruo *RegionUpdateOne) sqlSave(ctx context.Context) (_node *Region, err error) {
	_spec := sqlgraph.NewUpdateSpec(region.Table, region.Columns, sqlgraph.NewFieldSpec(region.FieldID, field.TypeInt64))
	id, ok := ruo.mutation.ID()
	if !ok {
		return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Region.id" for update`)}
	}
	_spec.Node.ID.Value = id
	if fields := ruo.fields; len(fields) > 0 {
		_spec.Node.Columns = make([]string, 0, len(fields))
		_spec.Node.Columns = append(_spec.Node.Columns, region.FieldID)
		for _, f := range fields {
			if !region.ValidColumn(f) {
				return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
			}
			if f != region.FieldID {
				_spec.Node.Columns = append(_spec.Node.Columns, f)
			}
		}
	}
	if ps := ruo.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	if value, ok := ruo.mutation.Name(); ok {
		_spec.SetField(region.FieldName, field.TypeString, value)
	}
	if value, ok := ruo.mutation.ParentRegion(); ok {
		_spec.SetField(region.FieldParentRegion, field.TypeString, value)
	}
	if ruo.mutation.ParentRegionCleared() {
		_spec.ClearField(region.FieldParentRegion, field.TypeString)
	}
	if value, ok := ruo.mutation.Latitude1(); ok {
		_spec.SetField(region.FieldLatitude1, field.TypeFloat64, value)
	}
	if value, ok := ruo.mutation.AddedLatitude1(); ok {
		_spec.AddField(region.FieldLatitude1, field.TypeFloat64, value)
	}
	if ruo.mutation.Latitude1Cleared() {
		_spec.ClearField(region.FieldLatitude1, field.TypeFloat64)
	}
	if value, ok := ruo.mutation.Longitude1(); ok {
		_spec.SetField(region.FieldLongitude1, field.TypeFloat64, value)
	}
	if value, ok := ruo.mutation.AddedLongitude1(); ok {
		_spec.AddField(region.FieldLongitude1, field.TypeFloat64, value)
	}
	if ruo.mutation.Longitude1Cleared() {
		_spec.ClearField(region.FieldLongitude1, field.TypeFloat64)
	}
	if value, ok := ruo.mutation.Latitude2(); ok {
		_spec.SetField(region.FieldLatitude2, field.TypeFloat64, value)
	}
	if value, ok := ruo.mutation.AddedLatitude2(); ok {
		_spec.AddField(region.FieldLatitude2, field.TypeFloat64, value)
	}
	if ruo.mutation.Latitude2Cleared() {
		_spec.ClearField(region.FieldLatitude2, field.TypeFloat64)
	}
	if value, ok := ruo.mutation.Longitude2(); ok {
		_spec.SetField(region.FieldLongitude2, field.TypeFloat64, value)
	}
	if value, ok := ruo.mutation.AddedLongitude2(); ok {
		_spec.AddField(region.FieldLongitude2, field.TypeFloat64, value)
	}
	if ruo.mutation.Longitude2Cleared() {
		_spec.ClearField(region.FieldLongitude2, field.TypeFloat64)
	}
	if value, ok := ruo.mutation.OsmData(); ok {
		_spec.SetField(region.FieldOsmData, field.TypeJSON, value)
	}
	if ruo.mutation.OsmDataCleared() {
		_spec.ClearField(region.FieldOsmData, field.TypeJSON)
	}
	if ruo.mutation.RegionTypeCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   region.RegionTypeTable,
			Columns: []string{region.RegionTypeColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(regiontype.FieldID, field.TypeInt64),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ruo.mutation.RegionTypeIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   region.RegionTypeTable,
			Columns: []string{region.RegionTypeColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(regiontype.FieldID, field.TypeInt64),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	if ruo.mutation.AccountIdCleared() {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   region.AccountIdTable,
			Columns: []string{region.AccountIdColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
			},
		}
		_spec.Edges.Clear = append(_spec.Edges.Clear, edge)
	}
	if nodes := ruo.mutation.AccountIdIDs(); len(nodes) > 0 {
		edge := &sqlgraph.EdgeSpec{
			Rel:     sqlgraph.M2O,
			Inverse: false,
			Table:   region.AccountIdTable,
			Columns: []string{region.AccountIdColumn},
			Bidi:    false,
			Target: &sqlgraph.EdgeTarget{
				IDSpec: sqlgraph.NewFieldSpec(user.FieldID, field.TypeInt),
			},
		}
		for _, k := range nodes {
			edge.Target.Nodes = append(edge.Target.Nodes, k)
		}
		_spec.Edges.Add = append(_spec.Edges.Add, edge)
	}
	_node = &Region{config: ruo.config}
	_spec.Assign = _node.assignValues
	_spec.ScanValues = _node.scanValues
	if err = sqlgraph.UpdateNode(ctx, ruo.driver, _spec); err != nil {
		if _, ok := err.(*sqlgraph.NotFoundError); ok {
			err = &NotFoundError{region.Label}
		} else if sqlgraph.IsConstraintError(err) {
			err = &ConstraintError{msg: err.Error(), wrap: err}
		}
		return nil, err
	}
	ruo.mutation.done = true
	return _node, nil
}
